package cn.tedu.hhmc.institution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.tedu.hhmc.base.response.JsonResult;
import cn.tedu.hhmc.institution.pojo.entity.Institution;
import cn.tedu.hhmc.institution.pojo.vo.InstitutionVO;
import cn.tedu.hhmc.institution.service.IInstitutionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 机构Controller
 * 
 * @author ruoyi
 * @date 2024-12-08
 */
@Slf4j
@RestController
@RequestMapping("/hhmc/institution")
public class InstitutionController
{
    @Autowired
    private IInstitutionService institutionService;

    /**
     * 查询全部机构列表
     */
    @GetMapping("/list")
    public JsonResult list()
    {
        log.debug("查询全部机构列表,参数:无");
        List<InstitutionVO> list = institutionService.selectInstitutionList(new Institution());
        return JsonResult.ok(list);
    }

    /**
     * 查询机构列表
     */
    @GetMapping("/select")
    public JsonResult select(Institution institution)
    {
        List<InstitutionVO> list = institutionService.selectInstitutionList(institution);
        return JsonResult.ok(list);
    }

    /**
     * 导出机构列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, Institution institution)
    {
        List<InstitutionVO> list = institutionService.selectInstitutionList(institution);
//        ExcelUtil<Institution> util = new ExcelUtil<Institution>(Institution.class);
//        util.exportExcel(response, list, "机构数据");
    }

    /**
     * 获取机构详细信息
     */
    @GetMapping(value = "/{id}")
    public JsonResult getInfo(@PathVariable("id") Long id)
    {
        return JsonResult.ok(institutionService.selectInstitutionById(id));
    }

    /**
     * 新增机构
     */
    @PostMapping
    public JsonResult add(@RequestBody Institution institution)
    {
        institutionService.insertInstitution(institution);
        return JsonResult.ok();
    }

    /**
     * 修改机构
     */
    @PutMapping
    public JsonResult edit(@RequestBody Institution institution)
    {
        institutionService.updateInstitution(institution);
        return JsonResult.ok();
    }

    /**
     * 删除机构
     */
	@DeleteMapping("/{ids}")
    public JsonResult remove(@PathVariable Long[] ids)
    {
        institutionService.deleteInstitutionByIds(ids);
        return JsonResult.ok();
    }
}
